<template>
        <ptitle title="中医大师"/>
        <textarea id="ask" rows="5" cols="50" placeholder="请描述你的病情" v-model="question"></textarea><br/>
        <button @click="askAi">发送</button>
        <hr/>
        <h6>中医咨询</h6>
        <load v-if="isLoading"/>
        <div id="answer" v-html="answer">
        </div>
</template>


<script>
   import axios from '../axios/index-ai.js'
   import load from '../components-ai/Loading.vue'
   import ptitle from '../components-ai/PageTitle.vue'
   export default {
      components:{load,ptitle}
      ,data(){
        return{
          question:""
          ,answer:""
        }
      },
      methods:{
        askAi:function(){
            this.isLoading=true;
            axios.post("https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions"
                    ,{
                        "model": "qwen-plus-2025-04-28",
                        "messages": [
                            {
                                "role": "system",
                                "content": "你是一个有经验的老中医，请用中医的角度为客户诊病，如果客户咨询的问题和病情无关，请你礼貌的拒绝回单."
                            },
                            {
                                "role": "user", 
                                "content": this.question
                            }
                        ]
                    }
            )
            .then(data=>{
                this.isLoading=false;
                this.answer=marked.parse(data.data.choices[0].message.content)
            })
         }
      }
      
   }
</script>

<style scoped>
  #answer{text-align:left}
</style>
